package com.xialinrui.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xialinrui.entity.TimeQuantum;
import com.xialinrui.mapper.TimeQuantumMapper;
import com.xialinrui.service.TimeQuantumService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Time;
import java.util.List;

/**
 * @author xialinrui
 */
@Service
public class TimeQuantumServiceImpl extends ServiceImpl<TimeQuantumMapper, TimeQuantum> implements TimeQuantumService {

    @Resource
    private TimeQuantumMapper timeQuantumMapper;

    @Override
    public void deleteLast() {
        QueryWrapper<TimeQuantum> timeQuantumQueryWrapper = new QueryWrapper<>();
        timeQuantumQueryWrapper.eq("status", 1);
        timeQuantumMapper.delete(timeQuantumQueryWrapper);
    }

    @Override
    public void insert(List<List<Time>> timeQuantumList) {
        for (List<Time> timeQuantum : timeQuantumList) {
            Time start = timeQuantum.get(0);
            Time end = timeQuantum.get(1);
            timeQuantumMapper.insert(new TimeQuantum(null, 1, start, end));
        }
    }
}
